package com.caojing.haolemai.ui.category.categoryadapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.caojing.haolemai.R;
import com.caojing.haolemai.bean.categorybean.CategoryResultsBean;
import com.caojing.haolemai.bean.categorybean.ThirdBean;
import com.caojing.haolemai.view.MyGridView;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by My on 2016/10/18.
 */
public class CategoryRightListAdapter extends BaseAdapter {
    private Context mContext;
    private List<CategoryResultsBean.SecondBean> secondBeanList;

    public CategoryRightListAdapter(Context context, List<CategoryResultsBean.SecondBean> list) {
        //Log.i("TAG", "CategoryLeftAdapter----->" + list.toString());
        this.mContext = context;
        this.secondBeanList = list;

    }

    @Override
    public int getCount() {
        return secondBeanList != null ? secondBeanList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return secondBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    /**
     * @param position
     * @param convertView
     * @param parent
     * @return
     */
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.category_right_list_item, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        CategoryResultsBean.SecondBean secondBean = secondBeanList.get(position);
        String name = secondBean.getVirtualName();
        viewHolder.tvCategoryRightList.setText(name);
        List<ThirdBean> third = secondBean.getThird();
        CategoryRightListGvAdapter adapter= new CategoryRightListGvAdapter(mContext,third);
        viewHolder.categoryListGv.setAdapter(adapter);

        return convertView;
    }


    static class ViewHolder {
        @Bind(R.id.tv_category_right_list)
        TextView tvCategoryRightList;
        @Bind(R.id.category_list_gv)
        MyGridView categoryListGv;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
